package com.suixun.vo.credits;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

/**
 * 新增,详情,商品档案vo
 * 
 * @author yh
 * @date 2017年12月13日
 */
public class GoodsArchivesVo implements Serializable {

    private static final long serialVersionUID = -4341699691224088285L;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 商品id
     */
    private Integer id;

    /**
     * jf_company_id
     */
    private Integer companyId;

    /**
     * 商品名称,64
     */
    private String name;

    /**
     * 商品档案序列号
     */
    private String uuid;

    /**
     * 商品类型:1免费券2特价券3抵用券4折扣券
     */
    private Short goodsType;

    /**
     * 需要消耗的积分数
     */
    private Integer consumeCredit;

    /**
     * 商品市场价
     */
    private BigDecimal price;

    /**
     * 有效期开始时间
     */
    private Date beginTime;

    /**
     * 有效期到期时间
     */
    private Date endTime;

    /**
     * 库存
     */
    private Integer num;

    /**
     * 缩略图地址
     */
    private String smallImg;

    /**
     * 商品介绍
     */
    private String contents;

    /**
     * 商品使用对象显示名, 0所有,1教师,2家长
     */
    private Integer putRange;

    /**
     * 商品投放地区标识
     */
    private String areaId;
    
    /**
     * 商品说明
     */
    private String instructions;

    /**
     * 适用对象
     * 0所有用户 1白卡用户 2学生证用户
     */
    private Short cardType;
    /**
     * 是否置顶
     */
    private Boolean isTop;
    /**
     * 商品属性
     */
    private Short cardProperty;
    /**
     * 商品使用时间，可以包含备注
     */
    private String useTime;
    /**
     * 商品有效期备注
     */
    private String validRemark;
    /**
     * 商品套餐内容,json对象
     */
    private String goodsPackage;
    
    

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Short getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(Short goodsType) {
        this.goodsType = goodsType;
    }

    public Integer getConsumeCredit() {
        return consumeCredit;
    }

    public void setConsumeCredit(Integer consumeCredit) {
        this.consumeCredit = consumeCredit;
    }

    // @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    public Date getBeginTime() {
        return beginTime;
    }

    // @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    public void setBeginTime(String beginTime) throws Exception {
        this.beginTime = sdf.parse(beginTime);
    }

    // @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    public Date getEndTime() {
        return endTime;
    }

    // @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    public void setEndTime(String endTime) throws Exception {
        this.endTime = sdf.parse(endTime);
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public String getSmallImg() {
        return smallImg;
    }

    public void setSmallImg(String smallImg) {
        this.smallImg = smallImg;
    }

    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        this.contents = contents;
    }

    public Integer getPutRange() {
        return putRange;
    }

    public void setPutRange(Integer putRange) {
        this.putRange = putRange;
    }

    public String getAreaId() {
        return areaId;
    }

    public void setAreaId(String areaId) {
        this.areaId = areaId;
    }
    
    public String getInstructions() {
        return instructions;
    }

    public void setInstructions(String instructions) {
        this.instructions = instructions;
    }

    public Short getCardType() {
        if(cardType == null){
            return 0;
        }
        return cardType;
    }

    public void setCardType(Short cardType) {
        this.cardType = cardType;
    }
    
    public Boolean getIsTop() {
		return isTop;
	}

	public void setIsTop(Boolean isTop) {
		this.isTop = isTop;
	}

	public Short getCardProperty() {
		return cardProperty;
	}

	public void setCardProperty(Short cardProperty) {
		this.cardProperty = cardProperty;
	}

	public String getUseTime() {
		return useTime;
	}

	public void setUseTime(String useTime) {
		this.useTime = useTime;
	}

	public String getValidRemark() {
		return validRemark;
	}

	public void setValidRemark(String validRemark) {
		this.validRemark = validRemark;
	}

	public String getGoodsPackage() {
		return goodsPackage;
	}

	public void setGoodsPackage(String goodsPackage) {
		this.goodsPackage = goodsPackage;
	}

	public boolean verify() {
        if (companyId == null || companyId < 1) {
            return false;
        }
        if (StringUtils.isEmpty(name) || name.length() > 64) {
            return false;
        }
        if (goodsType == null || !(goodsType < 5 && goodsType > 0)) {
            return false;
        }
        if (consumeCredit == null) {
            return false;
        }
        if (endTime == null || endTime.getTime() < beginTime.getTime()) {
            return false;
        }
        if (num == null || num < 0) {
            return false;
        }
        if (StringUtils.isEmpty(smallImg)) {
            return false;
        }
        if (StringUtils.isEmpty(contents)) {
            return false;
        }
        if ((StringUtils.isEmpty(areaId) && putRange != null) || (StringUtils.isNotEmpty(areaId) && putRange == null)) {
            return false;
        }
        if (putRange != null && !(putRange < 3 && putRange >= 0)) {
            return false;
        }
        if (StringUtils.isNotEmpty(instructions) && instructions.length() > 500) {
            return false;
        }
        if (cardType != null && !(cardType <= 2 && cardType >= 0)) {
            return false;
        }
        return true;
    }

    public boolean verifyUpdate() {
        if (id == null || id < 1) {
            return false;
        }
        return verify();
    }

}